<?php
/**
 * Created by PhpStorm.
 * User: liuwei
 * Date: 2022/12/16
 * Time: 14:19
 */

namespace App\Http\Controllers\Backend;

use App\Http\Requests\Company\PrivilegeRequest;
use App\Services\Member\Models\Privilege;
use App\Services\Business\Interfaces\QuestionServiceInterface;
use App\Services\Business\Services\QuestionService;
use Illuminate\Http\Request;



class PrivilegeController extends BaseController
{
    /**
     * @var QuestionService
     */
    protected $questionService;

    public function __construct(
        QuestionServiceInterface $questionService
    )
    {
        $this->questionService = $questionService;

    }

    public function index(Request $request)
    {
        $companyId = $this->loginCompanyId();
        $privileges =Privilege::query()->select(['id','title','icon','company_id'])->where('company_id',$companyId)->get();
        return $this->successData(compact('privileges' ));
    }

    public function store(PrivilegeRequest $request, Privilege $privilege)
    {
        $data = $request->filldata();
        $privilege->fill($data)->save();
        return $this->success("插入权限成功");
    }


    public function edit(Request $request, $id)
    {

        $privilege = Privilege::find($id);
        return $this->successData(compact("privilege"));

    }



    public function delete(Request $request, $id)
    {


        $privilege = Privilege::query()->where('id', $id)->firstOrFail();
        $privilege->delete();
        return $this->success(__('删除权限成功'));
    }

    public function update(PrivilegeRequest $request, $id)
    {
        $privilege = Privilege::query()->where('id', $id)->firstOrFail();
        $privilege->fill($request->filldata())->update();
        return $this->success(__('更新权限成功'));

    }













}